//utf-8
//点击新增按钮 事件跳转至 新增页面
function toAddData(){
	
	var dialogStruct={
		'display':contextRootPath+'/tCMmCostPlan/prepareExecute/toAdd',
		'width':800,
		'height':500,
		'title':'新增',
		'buttons':[
         {'text':'保存','action':doAddFrom,'isClose':true},
		 {'text':'关闭','isClose':true}
		]
	};
	
	var dialogAdd =jyDialog(dialogStruct).open();
}
//新增页面的保存操作
function doAddFrom(){
	//序列化 新增页面的form表单数据
	var params=$("#addNewsFormData").serialize();
	var url=contextRootPath+'/tCMmCostPlan/insertTCMmCostPlan';
	//通过ajax保存
	jyAjax(
		url,
		params,
		function(msg){
			//新增成功后，
			alert(msg.msg);
			var v_status = msg.status;
        	if(v_status.indexOf('ok') >-1){
        		//新增成功后 刷新页面 或 只查询 id为msg.data['id'] 的  数据
        		queryData();
        	}
  	});
}
//修改 事件
function toUpdateData(){
	var v_ids = iframe.iframeObj["table"].getSelectedIds().join(",");
	//如果没有选中 数据则
	if(v_ids == ""){
		alert("请选择待修改的数据！");
		return;
	}
	//如果选择多个 择提示
	if(v_ids.indexOf(",") > -1){
		alert("请选择一条数据！");
		return;
	}

	var dialogStruct={
			'display':contextRootPath+'/tCMmCostPlan/prepareExecute/toUpdate?id='+v_ids,
			'width':800,
			'height':500,
			'title':'修改',
			'buttons':[
			 {'text':'关闭','isClose':true}
			]
		};
		
	
	var dialogUpdate = jyDialog(dialogStruct).open();
}
//修改页面 的 保存操作
function doUpdateFrom(){
	//序列化 新增页面的form表单数据
	
	var params=$("#updateNewsFormData").serialize();
	var url=contextRootPath+'/tCMmCostPlan/updateTCMmCostPlan';
	//通过ajax保存
	jyAjax(
		url,
		params,
		function(msg){
			//保存成功后，执行查询页面查询方法
			alert(msg.msg);
        	var v_status = msg.status;
        	if(v_status.indexOf('ok') >-1){
        		//新增成功后 刷新页面 或 只查询 id为msg.data['id'] 的  数据
        		queryData();
        	}
  	});
}
//删除 事件
function deleteData(){
	var v_ids = iframe.iframeObj["table"].getSelectedIds().join(",");
	//如果没有选中 数据则
	if(v_ids == ""){
		alert("请选择待删除的数据！");
		return;
	}
	if(confirm("您确认要删除选择的数据吗？")){
        $.ajax({
            type:"POST",
            dataType : "json",
            url:contextRootPath+"/tCMmCostPlan/deleteTCMmCostPlan?ids="+v_ids,
            success:function(msg){
            	alert(msg.msg);
            	var v_status = msg.status;
            	//删除成功后
            	if(v_status.indexOf('ok') >-1){
            		iframe.iframeObj["table"].removeSelectedRow();
            	}
            	
            	
            }
        });
    }
}
//查看明细
function viewData(vId){
	var dialogStruct={
			'display':contextRootPath+'/tCMmCostPlan/prepareExecute/toView?id='+vId,
			'width':800,
			'height':500,
			'title':'查看明细',
			'buttons':[
			 {'text':'关闭','isClose':true}
			]
	};
		
	var dialogView = jyDialog(dialogStruct).open();
}
//重置债权结算计划
function restCostPlan(){
	
	var transferId = $("#textTransferId").val();
	if(transferId==""||transferId==null){
		alert("债权转让编号不能为空！");
		return ;
	}
	if(confirm("您确认要重置债权转让编号"+transferId+"的债权结算，还款计划数据（此数据不能恢复）？")){
		$.ajax({
	        type:"POST",
	        dataType : "json",
	        url:contextRootPath+"/tCMmCostPlan/restCostPlanByTransferId?transferId="+transferId,
	        success:function(msg){
	        	alert(msg.msg);
	        }
	    });
	}
	
}

//重置债权结算计划
function buildPlan(){
	if(confirm("您确认要实时生成还款计划和结算计划？")){
		$.ajax({
	        type:"POST",
	        dataType : "json",
	        url:contextRootPath+"/tCMmCostPlan/buildPlan",
	        success:function(msg){
	        	alert(msg.msg);
	        }
	    });
	}
	
}

function runSql(){
	var dealCode = $("input[name='dealCode']").val();
	var creditorCode = $("input[name='creditorCode']").val();
	var transferId = $("input[name='transferId']").val();
	var startDate = $("input[name='startDate']").val();
	var pageNum = $("input[name='pageNum']").val();
	
	var url = "";
	if(startDate==""||startDate==null){
		alert("当期还款起日不能为空！");
		return ;
	}
	if(confirm("确定执行脚本吗？")){
		$.ajax({
	        type:"POST",
	        dataType : "json",
	        url:contextRootPath+"/tempCostPlan/runCostPlanSql?startDate="+startDate+"&creditorCode="+creditorCode+"&pageNum="+pageNum+"&dealCode="+dealCode+"&transferId="+transferId,
	        success:function(msg){
	        	alert(msg.msg);
	        }
	    });
	}
}

//导出
function exportDate(){
	
	var startDate = $("input[name=startDate]").val();
	var startDateEnd = $("input[name=startDateEnd]").val();
	var creditorCode = $("input[name=creditorCode]").val();
	var transferId = $("input[name=transferId]").val();
	var currentTime = $("input[name=currentTime]").val();
	var creditStatus = $("select[name=creditStatus] option:selected").val();
	var packageNum = $("input[name=packageNum]").val();
	var cooperorgCode = $("select[name=cooperorgCode] option:selected").val();
	var contractCode = $("select[name=contractCode] option:selected").val();
	
	if(""==startDate || null ==startDate){
		alert("账单日始不能空！");
		return;
	}
	
	if(""==startDateEnd || null ==startDateEnd){
		alert("账单日终不能空！");
		return;
	}
	
	if(startDate>startDateEnd){
		alert("账单日始不能大于账单日终！");
		return;
	}
	
	if(""==cooperorgCode || null ==cooperorgCode){
		alert("机构编号不能空！");
		return;
	}
	if(""==contractCode || null ==contractCode){
		alert("合约编号不能空！");
		return;
	}
	
	var url = contextRootPath + '/tCMmCostPlan/exportCostPlan?startDate=' + startDate + 
	'&startDateEnd=' + startDateEnd + '&creditorCode=' + creditorCode + '&transferId=' + 
	transferId + '&currentTime=' + currentTime + 
	'&cooperorgCode='+ cooperorgCode + '&contractCode=' + contractCode + '&packageNum=' + packageNum;
	window.location = url;
}

//导入
function importData(){
	var importUrl = "tCMmSubsidiary/importDataDetail";
	var callBack = "callBack()";
	var dialogStruct={
			'display':contextRootPath+'/common/importExcelFile.jsp?&importUrl=' +importUrl + "&callBack="+callBack,
			'width':800,
			'height':400,
			'title':'导入数据',
			'isIframe':'true',
			'buttons':[{'text':'关闭','isClose':true}]
		};
		dialog_import =jyDialog(dialogStruct);
		dialog_import.open();
}

function callBack(){
	return "处理成功";
}

